import { defineStore } from 'pinia'

export const useAppStore = defineStore({
  id: 'app-system',
  state() {
    return {
      devicePixelRatio: 1,
      pixelRatio: 0.5, // 每px对应的rpx
      platform: '',
      statusBarHeight: 0,
      navBarHeight: 44,
      screenHight: '',
      screenWidth: '',
      deviceModel: ''
    }
  },
  actions: {
    async getSystemInfo() {
      const systemInfo = await uni.getSystemInfo()
      this.platform = systemInfo.platform
      this.devicePixelRatio = systemInfo.devicePixelRatio
      this.screenHight = systemInfo.screenHeight
      this.screenWidth = systemInfo.screenWidth
      this.deviceModel = systemInfo.deviceModel
      this.statusBarHeight = systemInfo.statusBarHeight
      this.pixelRatio = 750 / this.screenWidth

      if (systemInfo.platform === 'android') {
        this.navBarHeight = this.statusBarHeight + 50
      } else {
        this.navBarHeight = this.statusBarHeight + 45
      }
    }
  }
})
